<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
    <script type="text/javascript">
         function factorial2(n){
            if(n===1){return n}
            return n*factorial(n-1)
            }
        //尾递归
        function tailfactorial(n,total){
            if(n===1){return total}
            return tailfactorial(n-1,n*total)
        }
        function factorial(n){
            return tailfactorial(n,1)
        }
        console.log(factorial(5))
    </script>
    </body>
</html>